var windowName = "servicesSelect";
var Page
apiready = function(){
    onWindowShow(function () {
    })
    onWindowHide(function () {
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        //页面数据
        panel: ''
        ,show: true
        ,catShow: false
        ,subTitle:"全部"
        ,keyword:""
        ,location:""
        ,cur:999
        ,cats:[]
        ,hots:[]
    },{
        //页面方法
        "init":function () {
            var cats = getLocData("cacheCats");if (isTrue(cats)){Page.cats = cats;}
            var hots = getLocData("hots");if (isTrue(hots)){Page.hots = hots;}
            this.location = location.href
            getHotCategory()
            setTimeout(function () {
                Page.catShow = true
            },200)
        }
        ,scroll:function (item) {
            this.cur = item
            location.replace(this.location + "#item" + item);
        }
        ,search:function () {
            setOpenAnimFromBottom()
            goto("search")
        }
        ,gotoHot:function (id) {
            var parentIndex = 0;
            var sonIndex = 0;
            Page.cats.map(function (data,parentIndex) {
                data.sons.map(function (son,sonIndex) {
                    if (son.id == id) {
                        goto('services',{cat1:parentIndex,cat2:sonIndex})
                    }
                })
            })
        }
    })
    Page.init()
}

function getHotCategory() {
    apiGet("/app/hot/cat",{},function (res,code) {
        logJson(res)
        if (code == 200) {
            Page.hots = res.data;
            setLocData("hots",Page.hots)
        }
    })
}